function dir_F = CalcFImages (stack, stim_inds)
% calculate images to each stimulation condition
% stim_inds specify the activation frames in the following form:
%   [0 0 0 1 1 1 0 0 0 3 3 3 0 0 0 2 2 2 ..]
% where 0 are not stimulated frames, each numbers refers to a unique
%   condition

no_conditions = max(stim_inds);
dim = size(stack);
dir_F = zeros(dim(1),dim(2),no_conditions);

if dim(3) ~= length(stim_inds)
    error('stim_inds do not match number of total frames')
end

for ind = 1:no_conditions
    dir_F(:,:,ind) = mean(stack(:,:,stim_inds == ind), 3);
end

